package com.qiangqiang.controller;

import com.qiangqiang.dto.BanDTO;
import com.qiangqiang.dto.LateDTO;
import com.qiangqiang.service.LateService;
import com.qiangqiang.util.ResultVOUtil;
import com.qiangqiang.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by q on 2018/2/20.
 */
@RestController
@RequestMapping("/late")
public class LateController {

    @Autowired
    private LateService lateService;

    @PostMapping("/add")
    public ResultVO addLateRecord(@RequestParam("id") String sId){
        lateService.addLateRecord(sId);
        return ResultVOUtil.success();
    }

    @PostMapping("/findByTime")
    public ResultVO<List<LateDTO>> findByTimeQuantum(@RequestParam("startTime") String startTime,
                                                     @RequestParam("endTime") String endTime){
        return ResultVOUtil.success(lateService.findByTimeQuantum(startTime,endTime));
    }

    @RequestMapping("/findAll")
    public ResultVO<Page<LateDTO>> findAllBans(@RequestParam(value = "page", defaultValue = "0") int page,
                                              @RequestParam(value = "size",defaultValue = "10") int size){
        return ResultVOUtil.success(lateService.findAllLateRecord(page,size));
    }

    @RequestMapping("/findBySId")
    public ResultVO<List<LateDTO>> findByDId(@RequestParam("sId") String sId){
        return ResultVOUtil.success(lateService.findAllBySId(sId));
    }
}
